home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 4 / The Arsenal Files 4 (Arsenal Computer).ISO / casm / au116-as.exe / SWEEP.CPP < prev    next >
C/C++ Source or Header  |  1994-12-13  |  3KB  |  136 lines

  1. // BBSWEEP.CPP                                 1          1    6666
  2. // Dave Harris                                11         11   6
  3. // Compiled using Borland C++ ver 3.1       1 1        1 1   6666
  4. // 03-03-94                                  1     ..   1   6   6
  5. //                                           11111 .. 11111  666
  6. ////////////////////////////////////////////////////////////////////////
  7.  
  8. #include "au.hpp"
  9.  
  10. #define PROGRAM "BBSWEEP"   // Name of module
  11. /************************************************************************/
  12. /* need to malloc some of this */
  13.  
  14. typedef struct
  15. {
  16.     char command[127];
  17.     char greater_than;
  18.     char less_than;
  19.     char pipe;
  20.     BYTE into_command;
  21. } SWEEP_INFO;
  22.  
  23. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  24. static int sweep(AU *au, char * /* file_name */)
  25. {
  26.     SWEEP_INFO *in = (SWEEP_INFO *)au->info;
  27.  
  28.     if (!au->simulate)
  29.         au_printf(au, "\n");
  30.  
  31. //      au_printf(au, "@?6Processing @?1%s@?H\n", au->source_directory);
  32.  
  33.     check_for_key();
  34.     press_any_key(au);
  35.     if (!au->simulate)
  36.         execute_raw(au, in->command);
  37.  
  38.     return 0;
  39. }
  40. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  41. static BYTE parse_comm_line(AU *au, char option, char *cur_argv,
  42.                             PARSE_TYPE type)
  43. {
  44.     SWEEP_INFO *in = (SWEEP_INFO *)au->info;
  45.     int i;
  46.  
  47.     switch (type)
  48.     {
  49.     case PARSE_PARAM_OPTION:
  50.         switch (option)
  51.         {
  52.         case 'B':
  53.             au->pause = get_value(au, OFF | ON);
  54.             break;
  55.         case 'G':
  56.             in->greater_than=cur_argv[0];
  57.             break;
  58.         case 'L':
  59.             in->less_than=cur_argv[0];
  60.             break;
  61.         case 'P':
  62.             in->pipe=cur_argv[0];
  63.             break;
  64.         case '?':
  65.             au_syntax_message(au, "SWeep");
  66.             au_printf(au,
  67.                "@?H[@?3options@?H] [@?1paths(s)@?H] command [command parameters]\n\n");
  68.             au_param_heading(au);
  69.             au_printf(au,
  70.                "@?3-B@?Hon|off  Break at each directory\n"
  71.                "@?3-G@?H<char>  Greater than character, default = }\n"
  72.                "@?3-L@?H<char>  Less than character, default = { \n"
  73.                "@?3-P@?H<char>  Pipe character, default = ~\n\n"
  74.                "Where <char> is a single character\n");
  75.             exit (0);
  76.         default:
  77.             au_invalid_option(au, PROGRAM, option);
  78.         }
  79.         return TRUE;
  80.     case PARSE_FILESPEC:
  81.         if (!in->into_command)
  82.         {
  83.             if (dir_exists(au, cur_argv))
  84.                 au->process_list.add(cur_argv);
  85.             else
  86.                 in->into_command = TRUE;
  87.         }
  88.         if (in->into_command)
  89.         {
  90.             strcat(in->command, cur_argv);
  91.             strcat(in->command, " ");
  92.         }
  93.         return TRUE;
  94.     case PARSE_POST_CHECK:
  95.         if (au->process_list.head == NULL)
  96.             au->process_list.add(".");
  97.  
  98.         if (in->command[0] == '\0')
  99.         {
  100.             au_printf_error(au, "Execution command is missing");
  101.             exit (1);
  102.         }
  103.         /* get back the > < and | from the command to execute */
  104.         for (i = strlen(in->command)-1; i >= 0; i--)
  105.         {
  106.             if (in->command[i] == in->greater_than)
  107.                 in->command[i] = '>';
  108.             else if (in->command[i] == in->less_than)
  109.                 in->command[i] = '<';
  110.             else if (in->command[i] == in->pipe)
  111.                 in->command[i] = '|';
  112.         }
  113.         return TRUE;
  114.     }
  115.     return FALSE;
  116. }
  117. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  118. int main_sweep(AU *au, int argc, char *argv[])
  119. {
  120.     SWEEP_INFO *in;
  121.  
  122.     in = (SWEEP_INFO *)au_malloc(au, sizeof(SWEEP_INFO));
  123.     memset(in, '\0', sizeof(SWEEP_INFO));
  124.     au->info = in;
  125.     in->greater_than = '}';
  126.     in->less_than = '{';
  127.     in->pipe = '~';
  128.  
  129.     au->dirs_only = TRUE;
  130.  
  131.     generic_parse_comm_line(au, argc, argv, parse_comm_line);
  132.     process_files(au, sweep);
  133.     return 0;
  134. }
  135.  
  136.